package com.wcgksoft.source.DataCi;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.bytes.ByteArrayEncoder;
import org.springframework.stereotype.Component;

/**
 * @author 阿良
 * @version 1.0.0
 * @ClassName NettyServerInitializer.java
 * @Description 初始化netty服务
 * @createTime 2020年05月03日 19:18:00
 */
@Component
public class NettyServerInitializer extends ChannelInitializer<SocketChannel> {
  @Override
  protected void initChannel(SocketChannel ch) throws Exception {
    //创建管道
    ChannelPipeline pipeline = ch.pipeline();
    //管道Handler1
    pipeline.addLast("serverHandler1", new ServerHandler());
    //管道Handler2
    pipeline.addLast("serverHandler2", new ServerHandler2());
    //管道使用byte数组进行编码
    pipeline.addLast("byteArrayEncoder", new ByteArrayEncoder());
    //自定义解码器
    pipeline.addLast("decoder", new MyDecoder());
    //成功啦！！！
    System.out.println("success to initHandler!");
  }
}
